<?php

/**
 * @name SoftRank Plugin Center for Discuz! 7.2.0 GBK
 * @copyright 2008-2009 SoftRank Research Center
 * @author http://www.softrank.net
 * @version 1.0.0.0
 */

class PluginCenter
{
	var $d_ext_config;
	var $p_ext_config;
	var $d_extid;
	var $p_extid;
	var $allow_d_to_p;
	var $allow_p_to_d;
	
	function PluginCenter(&$db, &$ptablepre)
	{
		$this->Refresh($db, $ptablepre);
	}
	
	function Refresh(&$db, &$ptablepre)
	{
		global $_DCACHE;
		$this->d_ext_config = $_DCACHE['settings']['extcredits'];
		
		$query = $db->query("SELECT * FROM `{$ptablepre}extconfig`");
		while ($ext_config_reader = $db->fetch_array($query))
		{
			$this->p_ext_config[$ext_config_reader['extid']] = array
			(
				'name' => $ext_config_reader['name'],
				'rate' => $ext_config_reader['rate'],
				'allow_in' => $ext_config_reader['allow_in'],
				'allow_out' => $ext_config_reader['allow_out'],
				'enabled' => $ext_config_reader['enabled'],
			);
		}
		
		$query = $db->query("SELECT * FROM `{$ptablepre}config`");
		while ($config_reader = $db->fetch_array($query))
		{
			$this->{$config_reader['name']} = $config_reader['value'];
		}
	}
	
	function ToArray()
	{
		$center = array
		(
			'd_ext_config' => $this->d_ext_config,
			'p_ext_config' => $this->p_ext_config,
			'd_extid' => $this->d_extid,
			'p_extid' => $this->p_extid,
			'allow_d_to_p' => $this->allow_d_to_p,
			'allow_p_to_d' => $this->allow_p_to_d,
		);
		return $center;
	}
}

?>